#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N = 2e5 + 10;
int arr[N];
int n, m;
struct S
{
	int l, r, mv;
}tree[N*4];
void pushup(int u)
{
	tree[u].mv = max(tree[u << 1].mv, tree[u << 1 | 1].mv);
}
void build(int u, int l, int r)
{
	if (l == r) {
		tree[u] = { l,r,arr[l] };
	}
	else {
		tree[u] = { l,r };
		int mid = l + r >> 1;
		build(u << 1, l, mid);
		build(u << 1 | 1, mid + 1, r);
		pushup(u);
	}
}

int query(int u, int l, int r)
{
	if (tree[u].l >= l && tree[u].r <= r) {
		return tree[u].mv;
	}
	int ans = 0;
	int mid = tree[u].l + tree[u].r >> 1;
	if (l <= mid) {
		ans = max(ans, query(u << 1, l, r));
	}
	if (r > mid) {
		ans = max(ans, query(u << 1 | 1, l, r));
	}
	return ans;
}
void modify(int u, int x, int v)
{
	if (tree[u].l == tree[u].r) {
		tree[u].mv = v;
	}
	else {
		int mid = tree[u].l + tree[u].r >> 1;
		if (x <= mid) {
			modify(u << 1, x, v);
		}
		else {
			modify(u << 1 | 1, x, v);
		}
		pushup(u);
	}
}
int main()
{
	while (scanf("%d%d", &n, &m)!=EOF) {
		for (int i = 1; i <= n; i++) {
			scanf("%d", &arr[i]);
		}
		build(1, 1, n);
		while (m--) {
			char op[2];
			int l, r;
			scanf("%s", op);
			if (op[0] == 'Q') {
				scanf("%d%d", &l, &r);
				printf("%d\n", query(1, l, r));
			}
			else {
				scanf("%d%d", &l, &r);
				modify(1, l, r);
			}
		}
	}
	
	return 0;
}